﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.guide {
    import Engine.Classes.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Modules.guide.ui.*;
    import Engine.*;
    import com.adobe.utils.*;

    public class Guide extends GuideObject {

        protected var m_callbackHelper:GuideCallbackHelper;
        protected var m_reader:GuideActionReader;
        protected var m_triggers:Dictionary;
        protected var m_callbacks:Dictionary;
        protected var m_names:Dictionary;
        protected var m_sequences:Dictionary;
        protected var m_mask:GuideMask = null;
        private var m_loadingMask:GuideMask = null;
        private var m_disableZoomCount:int = 0;
        protected var m_arrows:Array;
        protected var m_dialogs:Array;
        protected var m_guideTiles:Array;
        private var m_lastUpdateTime:Number = 0;

        public function Guide():void{
            this.m_triggers = new Dictionary();
            this.m_callbacks = new Dictionary();
            this.m_names = new Dictionary();
            this.m_sequences = new Dictionary();
            this.m_arrows = new Array();
            this.m_dialogs = new Array();
            this.m_guideTiles = new Array();
            this.m_callbackHelper = new GuideCallbackHelper();
            this.m_callbackHelper.registerHandlers(this);
            this.m_reader = new GuideActionReader(this);
            this.m_reader.readActions();
        }
        public function isActive():Boolean{
            var _local1:GuideSequence;
            for each (_local1 in DictionaryUtil.getValues(this.m_sequences)) {
                if (_local1.isActive()){
                    return (true);
                };
            };
            return (false);
        }
        public function loadFirstStepAssets():void{
            Global.delayedAssets.startPreloadingUrls(GuideUtils.GUIDE_ASSETS_FIRST_STEP, LoadingManager.PRIORITY_HIGH);
        }
        public function loadLaterStepAssets():void{
            Global.delayedAssets.startPreloadingUrls(GuideUtils.GUIDE_ASSETS_LATER_STEPS, LoadingManager.PRIORITY_LOW);
        }
        public function notify(_arg1:String):void{
            var _local3:GuideSequence;
            if ((((_arg1 == null)) || ((_arg1.length < 1)))){
                return;
            };
            var _local2:Array = this.m_triggers[_arg1];
            if (_local2 != null){
                for each (_local3 in _local2) {
                    _local3.start();
                };
            };
        }
        public function update():void{
            var _local2:Number;
            var _local3:GuideSequence;
            var _local1:int = getTimer();
            if (this.m_lastUpdateTime > 0){
                _local2 = ((_local1 - this.m_lastUpdateTime) / 1000);
                this.m_lastUpdateTime = _local1;
                for each (_local3 in this.m_sequences) {
                    _local3.update(_local2);
                };
            } else {
                this.m_lastUpdateTime = _local1;
            };
        }
        public function cleanup():void{
            var _local1:GuideSequence;
            for each (_local1 in this.m_sequences) {
                _local1.cleanup();
            };
            this.removeMask();
            this.removeArrows();
            this.removeDialogs();
            this.removeGuideTiles();
        }
        public function displayLoadingMask():void{
            if (this.m_loadingMask == null){
                this.m_loadingMask = new GuideMask();
                this.m_loadingMask.displayMask(GuideConstants.MASK_GAME_AND_BOTTOMBAR);
                this.disableZoom();
            };
        }
        public function removeLoadingMask():void{
            if (this.m_loadingMask != null){
                this.m_loadingMask.removeMask();
                this.m_loadingMask = null;
                this.enableZoom();
            };
        }
        public function displayMaskWithParent(_arg1:DisplayObjectContainer, _arg2:int=-1, _arg3:Boolean=true):void{
            if ((((this.m_mask == null)) && (!((_arg1 == null))))){
                this.m_mask = new GuideMask();
                this.m_mask.displayMaskWithParent(_arg1, _arg2, _arg3);
                this.disableZoom();
            };
        }
        public function displayMaskUI(_arg1:int=0, _arg2:Number=0):void{
            if (this.m_mask == null){
                this.m_mask = new GuideMask();
                this.m_mask.displayMask(_arg1, _arg2);
                this.disableZoom();
            };
        }
        public function removeMask():void{
            if (this.m_mask != null){
                this.m_mask.removeMask();
                this.m_mask = null;
                this.enableZoom();
            };
        }
        public function removeArrows():void{
            var _local1:GuideArrow;
            for each (_local1 in this.m_arrows) {
                _local1.release();
            };
            this.m_arrows = [];
        }
        public function removeDialogs():void{
            var _local1:GenericDialog;
            for each (_local1 in this.m_dialogs) {
                _local1.close();
            };
            this.m_dialogs = [];
        }
        public function displaySpotLightObject(_arg1:WorldObject, _arg2:Point, _arg3:int, _arg4:int, _arg5:Number=0, _arg6:Boolean=false):void{
            var _local7:Vector3 = _arg1.getPosition();
            var _local8:Point = new Point(_local7.x, _local7.y);
            this.displaySpotLightOnTile(_local8, _arg2, _arg3, _arg4, _arg5, _arg6);
        }
        public function displaySpotLightOnTile(_arg1:Point, _arg2:Point, _arg3:int, _arg4:int, _arg5:Number=0, _arg6:Boolean=false):void{
            var _local7:Point = IsoMath.tilePosToPixelPos(_arg1.x, _arg1.y);
            _local7 = IsoMath.viewportToStage(_local7);
            this.displaySpotLight(Global.ui, _local7, _arg2, _arg3, _arg4, _arg5, _arg6);
        }
        public function displaySpotLight(_arg1:DisplayObjectContainer, _arg2:Point, _arg3:Point, _arg4:int, _arg5:int, _arg6:Number=0, _arg7:Boolean=false):void{
            if (this.m_mask != null){
                ErrorManager.addError("Spotlight applied twice!");
                return;
            };
            if (_arg1 == null){
                ErrorManager.addError("Failed to attach spotlight!");
            };
            this.m_mask = new GuideMask();
            this.m_mask.displaySpotLight(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7);
            this.disableZoom();
        }
        public function displayWeakSpotLight(_arg1:DisplayObjectContainer, _arg2:Point, _arg3:Point, _arg4:int, _arg5:int, _arg6:Number=0, _arg7:Boolean=false):void{
            if (this.m_mask != null){
                ErrorManager.addError("Spotlight applied twice!");
                return;
            };
            if (_arg1 == null){
                ErrorManager.addError("Failed to attach spotlight!");
            };
            this.m_mask = new WeakGuideMask(this);
            this.m_mask.displaySpotLight(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7);
            this.disableZoom();
        }
        public function displayLotArrow(_arg1:String, _arg2:Number, _arg3:Number, _arg4:Number=3, _arg5:Number=3, _arg6:int=3, _arg7:Boolean=false):GuideArrow{
            var _local8:Point = new Point(_arg2, _arg3);
            _local8 = IsoMath.viewportToStage(_local8);
            _local8 = Global.ui.globalToLocal(_local8);
            var _local9:GuideArrow = new GuideArrow(_arg1, _local8.x, _local8.y, _arg4, _arg5, _arg6, _arg7);
            this.trackArrow(_local9);
            return (_local9);
        }
        public function displayArrow(_arg1:String, _arg2:Number, _arg3:Number, _arg4:Number=3, _arg5:Number=3, _arg6:int=3, _arg7:Boolean=false):GuideArrow{
            var _local8:GuideArrow = new GuideArrow(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7);
            this.trackArrow(_local8);
            return (_local8);
        }
        public function displayGuideTile(_arg1:Vector3, _arg2:Number, _arg3:Number):GuideTile{
            var _local4:GuideTile = new GuideTile(_arg1, _arg2, _arg3);
            _local4.drawGuideTile(Constants.COLOR_VALID_PLACEMENT);
            this.trackGuideTile(_local4);
            return (_local4);
        }
        public function removeGuideTiles():void{
            var _local1:GuideTile;
            for each (_local1 in this.m_guideTiles) {
                _local1.cleanup();
            };
            this.m_guideTiles = [];
        }
        public function trackGuideTile(_arg1:GuideTile):void{
            this.m_guideTiles.push(_arg1);
        }
        public function get guideTiles():Array{
            return (this.m_guideTiles);
        }
        public function onResize():void{
            if (this.m_mask != null){
                this.m_mask.resize();
            };
        }
        public function trackArrow(_arg1:GuideArrow):void{
            this.m_arrows.push(_arg1);
        }
        public function getArrows():Array{
            return (this.m_arrows);
        }
        public function trackDialog(_arg1:GenericDialog):void{
            this.m_dialogs.push(_arg1);
        }
        public function registerTrigger(_arg1:String, _arg2:GuideSequence):void{
            if ((((_arg1.length < 1)) || ((_arg2 == null)))){
                return;
            };
            if (this.m_triggers[_arg1] == null){
                this.m_triggers[_arg1] = new Array();
                this.m_triggers[_arg1].push(_arg2);
            } else {
                this.m_triggers[_arg1].push(_arg2);
            };
        }
        public function registerSequence(_arg1:GuideSequence):void{
            if (_arg1 != null){
                if (this.m_sequences[_arg1.m_name] == null){
                    this.m_sequences[_arg1.m_name] = _arg1;
                    this.registerTrigger(_arg1.m_trigger, _arg1);
                };
            };
        }
        public function registerCallback(_arg1:String, _arg2:Function):void{
            if (((((!((_arg1 == null))) && ((_arg1.length > 0)))) && (!((_arg2 == null))))){
                if (this.m_callbacks[_arg1] == null){
                    this.m_callbacks[_arg1] = _arg2;
                };
            };
        }
        public function verifyCallback(_arg1:String):Function{
            if (((!((_arg1 == null))) && ((_arg1.length > 0)))){
                return (this.m_callbacks[_arg1]);
            };
            return (null);
        }
        public function unregisterCallback(_arg1:String):void{
            if (this.m_callbacks[_arg1] != null){
                delete this.m_callbacks[_arg1];
            };
        }
        public function registerObject(_arg1:String, _arg2:DisplayObject):void{
            if (((((!((_arg1 == null))) && ((_arg1.length > 0)))) && (!((_arg2 == null))))){
                this.m_names[_arg1] = _arg2;
            };
        }
        public function unregisterObject(_arg1:String):void{
            if (this.m_names[_arg1] != null){
                delete this.m_names[_arg1];
            };
        }
        public function getObjectByName(_arg1:String):DisplayObject{
            var firstChar:* = null;
            var hasHier:* = 0;
            var regname:* = null;
            var parts:* = null;
            var name:* = _arg1;
            if ((((name == null)) || ((name.length < 1)))){
                return (null);
            };
            try {
                firstChar = name.charAt(0);
                hasHier = name.indexOf(".");
                if ((((firstChar == "@")) && ((hasHier == -1)))){
                    regname = name.substr(1);
                    return (this.getObjectByRegistration(regname));
                };
                parts = name.split(".");
                return (this.getObjectByHier(parts));
            } catch(err:Error) {
                return (null);
            };
            return (null);
        }
        public function getObjectByRegistration(_arg1:String):DisplayObject{
            if ((((_arg1 == null)) || ((_arg1.length < 1)))){
                return (null);
            };
            return (this.m_names[_arg1]);
        }
        public function getObjectByHier(_arg1:Array):DisplayObject{
            var _local4:String;
            var _local5:String;
            if ((((_arg1 == null)) || ((_arg1.length < 1)))){
                return (null);
            };
            var _local2:DisplayObject;
            var _local3:DisplayObject;
            var _local6:int = _arg1.length;
            var _local7:int;
            while (_local7 < _local6) {
                _local5 = _arg1[_local7];
                _local4 = _local5.charAt(0);
                if (_local4 == "@"){
                    _local5 = _local5.substr(1);
                    _local2 = this.getObjectByRegistration(_local5);
                } else {
                    if (_local3 == null){
                        _local3 = Global.stage;
                    };
                    _local2 = GuideUtils.findChild((_local3 as DisplayObjectContainer), _local5);
                };
                if (_local2 == null){
                    return (null);
                };
                _local3 = _local2;
                _local7++;
            };
            return (_local2);
        }
        public function getActiveSequence():GuideSequence{
            var _local1:GuideSequence;
            for each (_local1 in DictionaryUtil.getValues(this.m_sequences)) {
                if (_local1.isActive()){
                    return (_local1);
                };
            };
            return (null);
        }
        protected function disableZoom():void{
            this.m_disableZoomCount++;
            if (this.m_disableZoomCount > 0){
                Global.world.enableZoom(false);
            };
        }
        private function enableZoom():void{
            this.m_disableZoomCount--;
            if (this.m_disableZoomCount <= 0){
                this.m_disableZoomCount = 0;
                Global.world.enableZoom(true);
            };
        }

    }
}//package Modules.guide 
